import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tin_flutter/ui/widget/common_product_vertical_widget.dart';
import 'package:tin_flutter/ui/widget/common_title_widget.dart';

import '../../../../../app/res/app_color.dart';
import '../../../../../app/res/intl.dart';
import '../../../../../app/tools/logger.dart';
import '../../main_logic.dart';

/// * 作者: Tao
/// * 日期: 2025/11/4
/// * 时间: 16:42
/// * 描述: 新鲜好物模块
class NewProductWidget extends StatefulWidget {

  const NewProductWidget({Key? key}) : super(key: key);

  @override
  State<NewProductWidget> createState() => _NewProductWidgetState();
}

class _NewProductWidgetState extends State<NewProductWidget> {
  final state = Get.find<MainLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.only(top: 8.0, bottom: 8.0),
      child: Container(
        decoration: BoxDecoration(
          color: AppColor.white,
          borderRadius: BorderRadius.all(Radius.circular(5.0)),
        ),
        child: Padding(
          padding: EdgeInsets.all(12.0),
          child: Column(
            children: [
              // 标题栏
              CommonTitleWidget(
                  imageUrl: 'assets/images/icon_new_product.png',
                  title: Intl().newProductTitle,
                  content: Intl().newProductContent,
                  onTap: () {
                    logger('点击了${Intl().newProductTitle}');
                  }),
              SizedBox(height: 5.0),
              // 横向列表
              SizedBox(
                  height: 220.0,
                  child: ListView.builder(
                      scrollDirection: Axis.horizontal,
                      shrinkWrap: true,
                      padding: EdgeInsets.all(5.0),
                      itemCount: state.newProductList.length,
                      itemBuilder: (context, index) {
                        return CommonProductVerticalWidget(
                            imageUrl: state.newProductList[index].pic,
                            title: state.newProductList[index].name,
                            content: state.newProductList[index].subTitle,
                            price: state.newProductList[index].price.toInt());
                      }))
            ],
          ),
        ),
      ),
    );
  }
}
